﻿using System;
using System.Collections.Generic;
using System.Text;

namespace PCR.Logic
{
    using PCR.Base;

    /// <summary>
    /// Standard curve class, a curve contains a group of data, 
    /// that could generate a chat present the relationship with Cell CT
    /// and Cell count
    /// </summary>
    internal class StdCurve : GuidObject, IStdCurve
    {
        /// <summary>
        /// Get or set the standard curve name
        /// </summary>
        public string Name 
        {
            get { return this._name; }
            set { this._name = value; }
        }
        string _name = string.Empty;

        /// <summary>
        /// Get or set the standard curve description
        /// </summary>
        public string Description 
        {
            get { return this._description; }
            set { this._description = value; }
        }
        string _description = string.Empty;

        /// <summary>
        /// Sample list, add or remove item from the list
        /// </summary>
        public IList<IStdSampleData> SampleDataList 
        {
            get { return this._sampleList; }
        }
        IList<IStdSampleData> _sampleList = new List<IStdSampleData>();

        /// <summary>
        /// Get or set the curve's parameter,
        /// We will calculate it from all the data
        /// </summary>
        public IStdCurveParam CurveParam 
        {
            get 
            { 
                IList<IStdSampleData> samples = new List<IStdSampleData>();
                
                foreach(IStdSampleData data in SampleDataList)
                {
                    if (data.Valid) samples.Add(data);
                }
                // Calculate the param directly from out internal data
                return PCRRoot.Instance.Calculator.GetStdParamFromSampleData(
                    samples); 
            }
        }

        /// <summary>
        /// Calculate the revised CT from the sample data and curve parameter
        /// </summary>
        public double GetRevisedCT(IStdSampleData sample, IStdCurveParam curveParam)
        {
            System.Diagnostics.Debug.Assert(sample != null);
            System.Diagnostics.Debug.Assert(curveParam != null);
            
            return PCRRoot.Instance.Calculator.GetRevisedCT(
                curveParam.KVal, curveParam.BVal, sample.CellCount);
        }
        
    }
}
